import { ajax2 , ajax} from '../../ajax';
// var  getSocket = require("/utils/index.js");

Page({
  data: {
    phone:'',
    password:'',
    deviceNumber:'',
    client_id:'',
    // url:"/login",
    type:1
  },
  getPhone(e) {
    this.setData({
      phone: e.detail.value
    })
  },
  getPassward(e) {
    this.setData({
      password: e.detail.value
    })
  },
  // 登录
  login() {
    let phone = this.data.phone;
    let password = this.data.password;
    let device = my.getStorageSync({ key: 'system' }).data;
    ajax('/login', { phone, password, device }, 'POST').then((res) => {
      let that = this;
      if(typeof res.data.status === 'undefined') {
          my.showToast({
            type: 'success',
            content: '登录成功',
            duration: 3000,
            success: () => {
              my.reLaunch({url:'../home/home?id=' +  device});
              // getSocket();
              // let params = {
              //   type:'login',
              //   login_type:'2',
              //   client_id: that.data.client_id,
              //   // client_id: 'ac122c110b5500016fcf',
              //   user_phone:'QCF420190927117689' //that.data.deviceNumber
              // }
              // console.log(params)
              // ajax2('/WorkPost',params,'POST').then((res) => {
              //   console.log(res)
              // })
             // my.navigateTo({url: '../home/home'});
              // my.redirectTo({url: '../home/home'});
            },
          });
         my.setStorageSync({key:'token', data:res.data.token});
      }else{
        my.showToast({
          type: 'fail',
          content: res.data.msg,
          duration: 3000
        });
      }
    }).catch((err) => {
      console.log(err)
    })
  },
  
  onLoad() {
    console.log('onload')
    let that = this;
   
     
  },
  onShow() {
    let that = this;
  },
   onHide() {
    // my.ix.offKeyEventChange();
    console.log('登录的键盘监听uuuuuuuuuuuuuuu')
  }
});
